yjx.service('urlCgService', ['$rootScope', '$location', '$timeout','$state', function ($rootScope, $location, $timeout,$state) {
    return {
        watch:function () {
            $timeout(function () {
                //强制在页面内更新路由信息
                var path = $location.path();
                if ($rootScope.path != path) {
                    $rootScope.path = path;
                    $rootScope.path1 = path.split('/')[1],
                        $rootScope.path2 = path.split('/')[2],
                        $rootScope.path3 = path.split('/')[3],
                        $rootScope.path4 = path.split('/')[4];

                }
            })
        },
        encodeUrl: function (absurl) {
        if (absurl.split('/#/') && absurl.split('/#/').length > 1) {
            var url = absurl.split('/#/')[1];
        } else {
            url =absurl.split('/')[1];
            //console.log("url======================="+url);
        }
        if (url.split('?') && url.split('?').length > 1) {
            var index = url.split('?')[0];
            var params = url.split('?')[1];
            console.log(params)
            console.log(index);
            if (params) {
                //console.log(params);
                if (params.split('&') && params.split('&').length > 0) {
                    //暂时没有多个传参
                    params.split('&')[0]
                    var parames = {};
                    var paramsArr = params.split('&');
                    for (var i in paramsArr) {
                        var key = paramsArr[i].split('=')[0];
                        var value = paramsArr[i].split('=')[1];
                        parames[key] = value;
                    }
                    //console.log(parames)
                    $state.go(index, parames);
                }
                else {
                    var key = params.split('=')[0];
                    var value = params.split('=')[1];
                    var parames = {};
                    parames[key] = value;
                    $state.go(index, parames);
                }
            } else {
                $state.go(index);
            }

        } else {
            //if(url){
            //
            //}
            //window.location.href = "http://www.genetuan.com/#/home"
            $state.go("index");
        }
    }
    }

}]);